/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.ui.fileTransmiting;

import client.ui.fileTransmiting.removingTransmitedFile.RemoveProducer;
import java.awt.Dimension;
import java.io.File;
import java.net.Socket;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author Александр Емельянов (mr.lex91@gmail.com)
 */
public abstract class TransmitedFile extends javax.swing.JPanel {
    /**
     * Creates new form TransmitedFile
     */
    public TransmitedFile(String userName, File f, RemoveProducer remProd, long size) {
        initComponents();
        this.f=f;
        this.nickName=userName;
	this.size=size;
        String text=userName+": "+f.getAbsolutePath();
        if (text.length()>43)
        {
            jLabel1.setToolTipText(text);
            text=text.substring(0,39)+"...";
        }
        jLabel1.setText(text);
        this.remProd = remProd;
        setPreferredSize(new Dimension(279, 61));
        jLabel1.setPreferredSize(new Dimension(249, 14));
	jProgressBar1.setMaximum(100);
	jProgressBar1.setMinimum(0);
    }
    public abstract void Start(Socket soc);

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jButton1 = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setMaximumSize(new java.awt.Dimension(279, 61));
        setMinimumSize(new java.awt.Dimension(279, 61));
        setPreferredSize(new java.awt.Dimension(279, 61));

        jLabel1.setText(" ");

        jButton1.setText("Отмена");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        synchronized(stop)
        {
            stop=true;
        }
        if (!started) remProd.remove(nickName, f.getAbsolutePath());
    }//GEN-LAST:event_jButton1ActionPerformed
    protected void setProgress(int proc)
    {
	jProgressBar1.setValue(proc);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration//GEN-END:variables
    protected String nickName;
    protected File f;
    protected Socket soc;
    protected Boolean stop=false;
    protected boolean started=false;
    protected RemoveProducer remProd;
    protected long size;
    protected final static int buf_len=0xffffff;
}
